package com.meteor.web.controller;

import com.meteor.pojo.Blog;
import com.meteor.pojo.Comment;
import com.meteor.service.BlogService;
import com.meteor.service.CommentService;
import com.meteor.service.TagService;
import com.meteor.service.TypeService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import javax.annotation.Resource;
import java.util.List;

/**
 * 博客内容首页
 */
@Controller
public class WebBlogController {

    @Resource
    private BlogService blogService;

    @Resource
    private TypeService typeService;

    @Resource
    private TagService tagService;

    @Resource
    private CommentService commentService;


    /**
     * 跳转到相应博客 内容页面
     */
    @GetMapping("/blog/{id}")
    public String blog(@PathVariable Long id, Model model) {
        Blog blog = blogService.getAndConvert(id);
        Integer views = blog.getViews();
        views += 1;
        blogService.updateBlogByView(views,id);
        model.addAttribute("blog",blog);
        List<Comment> comments = commentService.queryCommentByBlogId(blog.getId());
        model.addAttribute("comments",comments);
        return "blog";
    }
}



















